How to Check Windows Event Logs with PowerShell?

您所在的位置:网站首页 exchange windows How to Check Windows Event Logs with PowerShell?

How to Check Windows Event Logs with PowerShell?

2023-03-18 18:29| 来源: 网络整理| 查看: 265

You can also use the command to view the logs of remote servers. Let’s say, you need to get the event logs on each and every Exchange Transport server. Normally, you would go through every one of them.

Using a combination of the above commands along with the **Get-TransportService**, you will get the events from all the Transport servers.

The complete script is similar to the following.

~~~~ $servers = Get-TransportService; foreach ($server in $servers) {Write-Host "Scanning the event log of: " -NoNewLine; Write-Host $server; Get-EventLog system -ComputerName $server -After (Get-Date).AddHours(-12) | where {($_.EntryType -Match "Error") -or ($_.EntryType -Match "Warning")} | ft -wrap >> "C:/$server.csv"; Get-EventLog application -ComputerName $server -After (Get-Date).AddHours(-12) | where {($_.EntryType -Match "Error") -or ($_.EntryType -Match "Warning")} | ft -wrap >> "C:/$server.csv"} ~~~~

This will save the results from each Exchange Server where it matches the error and save it to the C drive with the server’s name prefix. You will get a similar output.

You can use the **Get-WinEvent** or **Get-EventLog** command, depending on the case. However, you can also use a mix of both.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3